package com.ynding.spring.idea.ddd.core.model.wechat.entity;

import com.ynding.spring.idea.ddd.common.aax.exception.BalanceException;
import com.ynding.spring.idea.ddd.core.model.bo.Entity;
import com.ynding.spring.idea.ddd.core.model.wechat.dp.WalletNumber;
import com.ynding.spring.idea.ddd.core.model.wechat.valobj.AssetVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * <p> </p>
 *
 * @author ynding
 * @version 2022/4/26
 **/
@ApiModel(value = "Wallet", description = "钱包")
@Data
public class Wallet implements Entity<WalletNumber> {

    @ApiModelProperty("ID")
    private WalletNumber id;

    @ApiModelProperty("余额")
    private Balance balance;

    @ApiModelProperty("账单明细")
    private Statement statement;

    private Wallet(){}

    /**
     * 付款
     * @param asset 资金
     * @throws BalanceException 异常
     */
    public void pay(AssetVO asset) throws BalanceException {
        balance.decrease(asset.getBalance());
        statement.add(asset);
    }

    /**
     * 入账
     * @param asset 资金
     * @throws BalanceException
     */
    public void receive(AssetVO asset) throws BalanceException {
        balance.increase(asset.getBalance());
        statement.add(asset);
    }
}
